
import static org.junit.Assert.*;
import org.junit.Test;

public class FourInLineTest {
	private GameLogicTeamRoDK logic;

	@Test
	public void testInitializeGame() {
		logic = new GameLogicTeamRoDK();
		logic.initializeGame(7, 6, 1);

		assertEquals(7, logic.getX());
		assertEquals(6, logic.getY());
		assertEquals(0, logic.getGameBoard()[0][0]);
		assertEquals(0, logic.getGameBoard()[1][1]);
	}

	@Test
	public void prepareCase01() {
		testInitializeGame();
		
		logic.insertCoin(0, 2);
		logic.insertCoin(1, 2);
		logic.insertCoin(2, 2);				

		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 1]);
		assertEquals(2, logic.getGameBoard()[1][logic.getY() - 1]);	
		assertEquals(2, logic.getGameBoard()[2][logic.getY() - 1]);
	}
	
	@Test
	public void decideNextMove() {
		prepareCase01();
		int nextMove = logic.decideNextMove();
		assertEquals(3, nextMove);	
	}

	@Test
	public void checkEvaluations() {
		prepareCase01();

		// assertEquals(-64, logic.evaluateLine2(1, 0, logic.getY() - 1, 1, 0));
		// assertEquals(+64, logic.evaluateLine2(2, 0, logic.getY() - 1, 1, 0));		
	}	
	
	@Test
	public void logicCase01() {
		prepareCase01();
		
		assertEquals(3, logic.getMaxColumn());	
		assertFalse(logic.isGameFinished());
	}

	@Test
	public void prepareCase02() {
		testInitializeGame();
		
		logic.insertCoin("a1", 2);
		logic.insertCoin("a2", 2);		
		logic.insertCoin("a3", 2);
		logic.insertCoin("b1", 2);

		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 1]);
		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 2]);	
		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 3]);
		assertEquals(2, logic.getGameBoard()[1][logic.getY() - 1]);
	}
	
	
	@Test
	public void logicCase02() {
		prepareCase02();

		assertEquals(4, logic.getNumberOfCoins(2));
		int columnToMove = logic.getMaxColumn();
		assertEquals(4, logic.getNumberOfCoins(2));
		
		assertEquals(0, columnToMove);
		assertFalse(logic.isGameFinished());
	}	
	
	@Test
	public void prepareCase03() {
		testInitializeGame();
		
		logic.insertCoin("a1", 2);
		logic.insertCoin("a2", 2);		
		logic.insertCoin("c1", 2);
		logic.insertCoin("d1", 2);

		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 1]);
		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 2]);	
		assertEquals(2, logic.getGameBoard()[2][logic.getY() - 1]);
		assertEquals(2, logic.getGameBoard()[3][logic.getY() - 1]);
	}
	
	@Test
	public void logicCase03() {
		prepareCase03();

		assertEquals(4, logic.getNumberOfCoins(2));		
		int columnToMove = logic.getMaxColumn();
		assertEquals(4, logic.getNumberOfCoins(2));		
		assertEquals(0, logic.getNumberOfCoins(1));
		
		assertEquals(1, columnToMove);	
		assertFalse(logic.isGameFinished());
	}
	
	@Test
	public void prepareCase04() {
		testInitializeGame();
		
		logic.insertCoin("a1", 2);
		logic.insertCoin("a2", 2);		
		logic.insertCoin("b1", 1);
		logic.insertCoin("b2", 1);
		logic.insertCoin("b3", 1);
		logic.insertCoin("c1", 2);

		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 1]);
		assertEquals(2, logic.getGameBoard()[0][logic.getY() - 2]);	
		assertEquals(1, logic.getGameBoard()[1][logic.getY() - 1]);
		assertEquals(1, logic.getGameBoard()[1][logic.getY() - 2]);
		assertEquals(1, logic.getGameBoard()[1][logic.getY() - 3]);		
		assertEquals(2, logic.getGameBoard()[2][logic.getY() - 1]);
	}
	
	@Test
	public void logicCase04() {
		prepareCase04();

		int columnToMove = logic.getMaxColumn();
		assertEquals(1, columnToMove);
		assertFalse(logic.isGameFinished());
		
		logic.insertCoin("b4", 1);
		assertTrue(logic.isGameFinished());		
	}
	
	// check game finished function
	@Test
	public void prepareCase05() {
		testInitializeGame();
		
		logic.insertCoin("c1", 2);
		logic.insertCoin("c2", 2);		
		logic.insertCoin("c3", 1);
		logic.insertCoin("d1", 1);
		logic.insertCoin("d2", 1);
		logic.insertCoin("d3", 1);
		logic.insertCoin("d4", 2);
		logic.insertCoin("d5", 1);		
		logic.insertCoin("e1", 2);		
		logic.insertCoin("e2", 2);		
		logic.insertCoin("e3", 1);		
		logic.insertCoin("f1", 2);		
		logic.insertCoin("f2", 1);		
		logic.insertCoin("f3", 2);		
		logic.insertCoin("f4", 2);		
		logic.insertCoin("g1", 1);		
		
		assertFalse(logic.isGameFinished());		
	}
	
	@Test
	public void testInitializeGame02() {
		logic = new GameLogicTeamRoDK();
		logic.initializeGame(7, 6, 2);

		assertEquals(7, logic.getX());
		assertEquals(6, logic.getY());
		assertEquals(0, logic.getGameBoard()[0][0]);
		assertEquals(0, logic.getGameBoard()[1][1]);
	}
	
	@Test
	public void prepareCase06() {
		testInitializeGame02();
		
		logic.insertCoin("d1", 1); logic.insertCoin("d2", 2);		
		logic.insertCoin("e1", 1); 
	}

	@Test
	public void prepareCase07() {
		testInitializeGame02();
		
		logic.insertCoin("a1", 1); logic.insertCoin("b1", 2);		
		logic.insertCoin("a2", 1); logic.insertCoin("b2", 2);
		logic.insertCoin("a3", 1); 
	}

	@Test
	public void logicCase07() {
		prepareCase07();
		
		assertEquals(-1, logic.getForcedMove(-logic.getMaxval()));
		assertEquals( 0, logic.getForcedMove( logic.getMaxval()));		
		assertEquals( 0, logic.decideNextMove());		
	}
}
